/*
 * rosa.h
 *
 * Created: 2014-12-03 13:45:00
 *  Author: Andreas Domfors
 */ 


#ifndef ROSA_H_
#define ROSA_H_

/************************************************************************/
/*                    ROSA PUBLIC API                                   */
/************************************************************************/

/// Creates a new task and queues it for execution
int ROSA_taskCreate(char *taskName, void *taskFunction, unsigned int priority,
	unsigned int stackSize);
	
/// Terminates the currently executing task
void ROSA_taskTerminate(void);

/// Starts the scheduler
void ROSA_startScheduler(void);

/// Initializes ROSA. Should be called before calling driver functions
void ROSA_init(void);

/************************************************************************/
/*                    TIMERS AND DELAYS                                 */
/************************************************************************/

typedef unsigned long int timerType;

/// Delays the currently executing task by ticksToDelay ticks
void ROSA_taskDelay(timerType ticksToDelay);

/// Delays the currently executing task until the current tick count equals (ticks + period)
void ROSA_taskDelayUntil(timerType previusTime, timerType ticksToDelay);

/// Returns current tick value
timerType ROSA_getCurrentTick(void);

/************************************************************************/
/*                    SEMAPHORES                                        */
/************************************************************************/

typedef void *semaphore;

/// Creates and initializes a semaphore at the specified
/// address. The semaphore is available when created.
/// s must point at
int ROSA_createBinarySemaphore(semaphore *s);

/// Waits for the specified binary semaphore. If (timeout) ticks
/// pass without the semaphore becoming available, the operation
/// times out.
int ROSA_waitBinarySemaphore(semaphore *s, unsigned int timeout);

/// Signals the specified binary semaphore.
int ROSA_signalBinarySemaphore(semaphore *s);

typedef void *IPCPsemaphore;

/// Creates and initializes an IPCP semaphore at the location s.
/// The semaphore is available when created.
int ROSA_createSemaphoreIPCP(IPCPsemaphore *s, unsigned int ceiling);

/// Waits for the specified IPCP semaphore. If (timeout) ticks
/// pass without the semaphore becoming available, the operation
/// times out.
int ROSA_waitSemaphoreIPCP(IPCPsemaphore *s, unsigned int timeout);

/// Signals the specified IPCP semaphore. The task that calls this must
/// be the last task that successfully waited for the semaphore.
int ROSA_signalSemaphoreIPCP(IPCPsemaphore *s);

#endif /* ROSA_H_ */